<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<th:block th:replace="headfoot/head::head_common">引用公共的homefoot</th:block>
</head>

<body>
	<div class="container-fluid kj-form-container">
		<form
			id="userForm"
			class="form-horizontal validate kj-form-container-content"
			role="form"
			method="post"
			action="/system/user/save"
		>
				
			<input type="hidden" id="id" name="id" th:value="${entity?.id}" />
			
			<div class="from-group row has-feedback kj-form-title-button-bar">
				<div class="col-md-7">
					<button
						type="button"
						class="btn btn-default btn-sm action-ajax-form kj-btn-save"
					>
						<i class="iconfont icon-baocun"></i>&ensp;保存
					</button>
					<button
						type="button"
						class="btn btn-default btn-sm action-close-tab kj-btn-cancel"
					>
						<i class="iconfont icon-guanbi"></i>&ensp;取消
					</button>
				</div>
				<div class="col-md-5">
					<label class="col-md-6 control-label kj-form-title-button-bar-label">负责人： <span
						th:text="${entity?.createUserId != null ? entity?.createUserId : ''}"></span>
					</label> <label class="control-label kj-form-title-button-bar-label">创建时间：
						<span th:text="${entity?.createDate != null ? #dates.format(entity?.createDate, 'yyyy-MM-dd HH:mm:ss') : #dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd HH:mm:ss')}"></span>
					</label>
				</div>
			</div>

			<div class="card kj-form-container-card">
				<div class="card-header kj-form-container-card-header">
					<h4>
						<strong>用户详情</strong>
					</h4>
				</div>
				<div class="card-body kj-form-container-card-body">
					<div class="form-group">
						<label class="col-md-2 control-label kj-form-container-content-label">登录名</label>
						<div class="col-md-3 validateDiv">
							<input
								class="form-control input-sm kj-form-container-content-input"
								name="userName"
								type="text"
								data-rule-required="true" 
								autocomplete="off"
								placeholder="登录名"
								th:value="${entity?.userName}" />
						</div>
						
						<label class="col-md-2 control-label kj-form-container-content-label">姓名</label>
						<div class="col-md-3 validateDiv">
							<input
								class="form-control input-sm kj-form-container-content-input"
								name="name"
								type="text"
								data-rule-required="true" 
								autocomplete="off"
								placeholder="姓名"
								th:value="${entity?.name}" />
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-md-2 control-label kj-form-container-content-label">邮箱</label>
						<div class="col-md-3 validateDiv">
							<input
								class="form-control input-sm kj-form-container-content-input"
								name="email"
								type="text"
								data-rule-required="true" 
								autocomplete="off"
								placeholder="邮箱"
								th:value="${entity?.email}" />
						</div>
						 
						<label class="col-md-2 control-label kj-form-container-content-label">性别</label>
						<div class="col-md-3 validateDiv">
							<select
								class="form-control input-sm kj-form-container-content-input"
								name="gender"
								data-rule-required="true"
								data-option="请选择"
								th:value="${entity?.gender}"
								kjlink:pcode="gender"
							></select>
						</div>
					</div>
					
					<div class="form-group">
						<label class="col-md-2 control-label kj-form-container-content-label">用户类别</label>
						<div class="col-md-3 validateDiv">
							<select
								class="form-control input-sm kj-form-container-content-input"
								name="type"
								data-rule-required="true"
								data-option="请选择"
								kjlink:pcode="userType"
								onchange="$('#queryCompany').prop('disabled', this.value == 'Internal-Staff')"
							></select>
								<!-- th:value="${entity?.type}" -->
						</div>
						
						<label class="col-md-2 control-label kj-form-container-content-label">所属公司</label>
						<div class="col-md-3">
							<div class="input-group">
								<!-- <input name="fkCompanyId" type="hidden" th:value="${entity?.fkCompanyId}" /> -->
								<!-- <input class="form-control" id="fkCompanyName" type="text" readonly="readonly" th:value="${entity?.fkCompanyName}"> -->
								<input
									class="form-control"
									id="fkCompanyName"
									type="text"
									readonly="readonly"
									th:disabled="${false}">
								<div class="input-group-btn">
									<button id="queryCompany" type="button" class="btn btn-default"
										th:disabled="${false}"
									>选择</button>
									<!-- ${(entity?.type == null || entity?.type == 'Internal-Staff')} -->
								</div>
							</div>
						</div>
					</div>
						
					<div class="form-group">
						<label class="col-md-2 control-label kj-form-container-content-label">所属部门</label>
						<div class="col-md-3">
							<div class="input-group">
								<!-- <input name="fkOrganizationId" type="hidden" th:value="${entity?.fkOrganizationId}" /> -->
								<!-- <input class="form-control" id="fkOrganizationName" type="text" readonly="readonly" th:value="${entity?.fkOrganizationName}"> -->
								<input
									class="form-control"
									id="fkOrganizationName"
									type="text"
									readonly="readonly"
									th:disabled="${false}">
								<div class="input-group-btn">
									<button id="queryOrga" type="button" class="btn btn-default"
										th:disabled="${false}"
									>选择</button>
								</div>
							</div>
						</div>
						
						<label class="col-md-2 control-label kj-form-container-content-label">说明</label>
						<div class="col-md-3 validateDiv">
							<textarea
								class="form-control input-sm kj-form-container-content-input"
								name="memo"
								type="text"
								data-rule-required="true" 
								autocomplete="off"
								placeholder="说明"
								th:value="${entity?.memo}"
							></textarea>
						</div>
					</div>
					
				</div>
				
				<th:block th:if="${entity?.id}">
					<div class="card-header kj-form-container-card-header">
						<h4>
							<strong>用户角色</strong>
						</h4>
					</div>
					<div class="card-body kj-form-container-card-body">
						<div class="form-group">
							<div class="col-md-12">
								<div
									id="kj_list_content_btn_container"
									class="kj-list-content-btn-container form-group col-sm-12">
						            <button
										type="button"
										class="btn btn-sm btn-default"
										onclick="addRole()"
									>
										<i class="iconfont icon-tianjia"></i>&ensp;添加
									</button>
						
									<button
										class="btn btn-sm btn-default kj-btn-del bootable-action-post"
										type="button"
										data-table="#roleTable"
										th:data-href="${'/system/user/batchDeleteRole?userId=' + entity?.id}"
										data-confirm="确认删除吗"
									>
										<i class="iconfont icon-shanchu"></i>&ensp;删除
									</button>
								</div>
								
								<table
									id="roleTable"
									class="table table-bordered table-hover table-striped bootstrapTable"
									data-list-url="/system/role/list"
									th:data-del-url="${'/system/user/deleteRole?userId=' + entity?.id}"
									data-toolbar="#fkUserQueryForm"
								>
									<thead>
										<tr>
											<th data-checkbox="true"></th>
											<th data-field="roleName" data-sortable="true">角色名称</th>
											<th data-field="roleCode" data-sortable="true">角色代码</th>
											<th data-field="roleDescription" data-sortable="true">角色描述</th>
											<th data-field="enableFlag" data-formatter="showEnbale"
												data-sortable="true">状态</th>
											<th data-field="createDate" data-sortable="true">创建时间</th>
											<th data-field="operate" data-formatter="userRoleOperate"
												data-events="defaultOperateEvent">操作</th>
										</tr>
									</thead>
								</table>
							</div>
						</div>
					</div>
					
					<div class="card-header kj-form-container-card-header">
						<h4>
							<strong>用户岗位</strong>
						</h4>
					</div>
					<div class="card-body kj-form-container-card-body">
						<div class="form-group">
							<div class="col-md-12">
								<div
									id="kj_list_content_btn_container"
									class="kj-list-content-btn-container form-group col-sm-12">
						            <button
										type="button"
										class="btn btn-sm btn-default"
										onclick="addPosition()"
									>
										<i class="iconfont icon-tianjia"></i>&ensp;添加
									</button>
						
									<button
										class="btn btn-sm btn-default kj-btn-del bootable-action-post"
										type="button"
										data-table="#roleTable"
										th:data-href="${'/system/user/batchDeletePosition?userId=' + entity?.id}"
										data-confirm="确认删除吗"
									>
										<i class="iconfont icon-shanchu"></i>&ensp;删除
									</button>
								</div>
								
								<table
									id="positionTable"
									class="table table-bordered table-hover table-striped bootstrapTable"
									data-list-url="/system/position/list"
									th:data-del-url="${'/system/user/deletePosition?userId=' + entity?.id}"
									data-toolbar="#fkUserQueryForm"
								>
									<thead>
										<tr>
											<th data-checkbox="true"></th>
											<th data-field="name" data-sortable="true">岗位名称</th>
											<th data-field="code" data-sortable="true">岗位代码</th>
											<th data-field="type" data-sortable="true">岗位类型</th>
											<th data-field="memo" data-sortable="true">岗位描述</th>
											<th data-field="enableFlag" data-formatter="showEnbale"
												data-sortable="true">状态</th>
											<th data-field="createDate" data-sortable="true">创建时间</th>
											<th data-field="operate" data-formatter="userPositionOperate"
												data-events="defaultOperateEvent">操作</th>
										</tr>
									</thead>
								</table>
							</div>
						</div>
					</div>
				</th:block>
			</div>
		</form>
		<form id="fkUserQueryForm">
			<input type="hidden" name="fkUserId" th:value="${entity?.id}" />
		</form>
	</div>

	<script th:inline="javascript" type="text/javascript">
        
        function userRoleOperate(value, row, index, field) {
        	let html ='<a  href="#!" data-id="' + row.id +
        		'" class="btn btn-xs btn-default del-btn in-table" title="删除" data-toggle="tooltip" data-confirm="确认删除本地记录吗?"><i class="mdi mdi-window-close"></i></a>';
        	return html;
        }
        
        function userPositionOperate(value, row, index, field) {
        	let html ='<a  href="#!" data-id="' + row.id +
        		'" class="btn btn-xs btn-default del-btn in-table" title="删除" data-toggle="tooltip" data-confirm="确认删除本地记录吗?"><i class="mdi mdi-window-close"></i></a>';
        	return html;
        }
        
        function addRole() {
        	var url = base_url + "/system/role/roleListModal?userId=" + $("#id").val();
        	common.confirm("url:" + url, function() {
        		var rows = $("#roleModalTable").bootstrapTable('getSelections');
        		if (rows.length == 0) {
        			$.alert("请至少选择一行数据", "提示");
        			return false;
        		}
        		
        		var data = {
        				userId: $("#id").val(),
        				ids: rows.map(function(val) {
        					return val["id"];
        				})
				};
        		
        		var resultFlag = false;
        		$request.postSync(base_url + "/system/user/addRole", {data: data}, function(data) {
        			if (data.code == 0) {
				        resultFlag = true;
        			}
        			common.alert(data, function() {
        				$("#roleTable").bootstrapTable('refresh');
        			}, true);
        		});
        		return resultFlag;
        		
        	}, {title: '添加用户角色', closeIcon: true,columnClass: 'col-md-12 col-md-offset-0'});
		}
        
        function addPosition() {
        	var url = base_url + "/system/position/positionListModal?userId=" + $("#id").val();
        	common.confirm("url:" + url, function() {
        		var rows = $("#positionModalTable").bootstrapTable('getSelections');
        		if (rows.length == 0) {
        			$.alert("请至少选择一行数据", "提示");
        			return false;
        		}
        		
        		var data = {
        				userId: $("#id").val(),
        				ids: rows.map(function(val) {
        					return val["id"];
        				})
				};
        		
        		var resultFlag = false;
        		$request.postSync(base_url + "/system/user/addPosition", {data: data}, function(data) {
        			if (data.code == 0) {
				        resultFlag = true;
        			}
        			common.alert(data, function() {
        				$("#positionTable").bootstrapTable('refresh');
        			}, true);
        		});
        		return resultFlag;
        		
        	}, {title: '添加用户岗位', closeIcon: true,columnClass: 'col-md-12 col-md-offset-0'});
		}        	
    </script>
	<th:block th:replace="headfoot/foot::form_foot">引用公共的foot</th:block>


</body>
</html>